<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/common/commonConfig.jsp" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
	<head>
		<base href="<%=basePath%>">
		<title>更新用户</title>
		<script src="<%=basePath%>component/layout.js"></script>
    	<script src="<%=basePath%>component/toolbar.js"></script>
		<script type="text/javascript" src="<%=basePath%>dwrsystem/interface/userService.js"></script> 
		<script type="text/javascript" src="<%=basePath%>dwrsystem/engine.js"></script>
		<script type="text/javascript" src="<%=basePath%>js/validateJS.js"></script>
		<script type="text/javascript" src="<%=basePath%>js/tableForm.js"></script>
	<script type="text/javascript">
	var unitId;
	var dhxLayout = createLayoutNormal('1C',false,true);
							
	function configLayout(){
		var a = dhxLayout.cells('a');
		a.hideHeader();
		a.setText('主页面');
		a.fixSize(true, true);
		createToolbarFromDHXLayoutCell(a,function(toolbar){
		    toolbar.addText("info", 1, "操作:");
		    toolbar.addSeparator("sep1", 2);
	    	toolbar.addButton("update", 4, "修改", "settings.gif", "settings.gif");
	    	toolbar.addButton("submit", 5, "提交", "save.gif", "save_dis.gif");
	    	toolbar.addButton("cancel", 6, "取消", "undo.gif", "undo_dis.gif");
	    	toolbar.hideItem('submit');
	    	toolbar.hideItem('cancel');
		    toolbar.attachEvent("onClick", function(id) {
		    	if(id == 'update'){
		    		tableForm.tableToForm();
		    		toolbar.showItem('submit');
		    		toolbar.showItem('cancel');
		    		toolbar.hideItem('update');
		    	}
		    	if(id == 'cancel'){
		    		tableForm.formReturnTable();
		    		toolbar.showItem('update');
		    		toolbar.hideItem('cancel');
		    		toolbar.hideItem('submit');
		    	}
		    	if(id == 'submit'){
		    		validateEdit();
		    	}
		    });
		});
		a.attachObject('dataObj');
	}
	
	function resetPassword(){
		document.getElementById('newPassword').value='123456';
		document.getElementById('resetPasswordDiv').style.display='none';
		document.getElementById('showpass').style.display='';
	}
	
	function unResetPassword(){
		document.getElementById('newPassword').value="";
		document.getElementById('resetPasswordDiv').style.display='';
		document.getElementById('showpass').style.display='none';
	}


	
	function validateChangeLoginName(){
		var  nameWrong = document.getElementById('nameWrong') ;
		nameWrong.innerHTML='<img height="15" width="15" src="<%=basePath%>theme/${user.themeAddr }/images/editWaitingImg.gif" />';
		var uloginname = document.getElementById('userForm.loginName').value;
		if(trim(uloginname)==''){nameWrong.innerHTML='请输入登录名称';return false;}
		
		if (!validatePattern.validateChinese(uloginname,false)){
			nameWrong.innerHTML='登录名称非法，输入只能是[汉字]';
			return false;
		}
		userService.selectTUserExistForUpdate({loginName:uloginname, userMainId:document.getElementById('userForm.userMainId').value}, function(data){
			if(data == 1){
				nameWrong.innerHTML='存在相同的登录名称';
			}
			else{
				nameWrong.innerHTML='<img height="15" width="15" src="<%=basePath%>theme/${user.themeAddr }/images/ok.png" />';
			}
		});
	}
	
	function validateChangeLoginCode(){
		var codeWrong = document.getElementById('codeWrong');
		codeWrong.innerHTML='<img height="15" width="15" src="<%=basePath%>theme/${user.themeAddr }/images/editWaitingImg.gif" />';
		var ulogincode = document.getElementById('userForm.loginCode').value;
		if(trim(ulogincode)==''){
			codeWrong.innerHTML='请输入登录账号';
			return false;
		}
		
		if (!validatePattern.validateInputZZ(ulogincode,false)){
			codeWrong.innerHTML='登录账号非法，输入只能是[汉字,数字、26个英文字母或者下划线]';
			return false;
		}
		userService.selectTUserExistForUpdate({loginCode:ulogincode, userMainId:document.getElementById('userForm.userMainId').value}, function(data,right){
			if(data == 1){
				codeWrong.innerHTML='存在相同的登录账号';
			}else{
				codeWrong.innerHTML='<img height="15" width="15" src="<%=basePath%>theme/${user.themeAddr }/images/ok.png" />';
			}
		});
		
	}
	
	function validateEdit(){
		
		var ulogincode = document.getElementById('userForm.loginCode').value;
		if(trim(ulogincode)==''){myAlert('请输入登录账号');return;}
		if (!validatePattern.validateInputZZ(ulogincode,false)){
			myAlert('登录账号非法，输入只能是[汉字,数字、26个英文字母或者下划线]');
			return ;
		}
		
		var uloginname = document.getElementById('userForm.loginName').value;
		if(trim(uloginname)==''){myAlert('请输入登录名称');return;}
		if (!validatePattern.validateChinese(uloginname,false)){
			myAlert('登录名称非法，输入只能是[汉字]');
			return ;
		}

		layoutProgressOn(dhxLayout);
		userService.selectExistTUserForUpdate({loginCode:ulogincode, userMainId:document.getElementById('userForm.userMainId').value}, function(data){
			if(data == 1){
				myAlert('存在相同的登录账号');layoutProgressOff(dhxLayout);
				return;
			}else{
				userService.selectExistTUserForUpdate({loginName:uloginname, userMainId:document.getElementById('userForm.userMainId').value}, function(data){
					if(data == 1){
						myAlert('存在相同的登录名称');layoutProgressOff(dhxLayout);
						return;
					}else{
						document.forms["editForm"].submit();
						if(uloginname != '${userEdit.loginName}'){
							parent.parent.document.getElementById('uLoginName').innerHTML = uloginname;
						}
					}
				});
			}
		});
	}
	$(function (){
		configLayout();
		unitId = parent.window.unitId;
	});
	</script>		
	</head>

	<body>
		<div id="dataObj">
	  	<div id="displayDiv" class="formlayout" style="width:100%;height:100%;">
	  		<c:if test="${!empty userEdit}" >
	  			<form action="<%=basePath%>system-personalInfo/PersonalInfoAction!userEditPersonalUserInfo.action" method="post" name="editForm">
				<input type="hidden" name="userForm.userMainId" id="userForm.userMainId" value="${userEdit.userMainId }"/>
				<input type="hidden" name="userForm.loginPassword" id="userForm.loginPassword" />
				<input type="hidden" name="userForm.loginCodePassed" id="userForm.loginCodePassed" value="${userEdit.loginCode }" />
				<table>
					<tr>	
						<th>登录账号</th>
						<td>${userEdit.loginCode }
							<input type="hidden" name="editFormHidden"
						 		value="[{type:'input',id:'userForm.loginCode',name:'userForm.loginCode',value:'${userEdit.loginCode }',showText:'${userEdit.loginCode }',maxlength:'25',mustEnter:'yes'}]"/>
						</td>
					</tr>
					<tr>	
						<th>登录姓名 </th>
						<td>${userEdit.loginName }
						<input type="hidden" name="editFormHidden"
						 value="[{type:'input',id:'userForm.loginName',name:'userForm.loginName',value:'${userEdit.loginName }',showText:'${userEdit.loginName }',maxlength:'25',mustEnter:'yes'}]"/>
						</td>
					</tr>
					<tr>	
						<th>激活时间 </th><td><fmt:formatDate value="${userEdit.activeDate }" pattern="yyyy-MM-dd"/>
						</td>
					</tr>
					<tr>
						<th>失效时间 </th>
						<td><fmt:formatDate value="${userEdit.inactiveDate }" pattern="yyyy-MM-dd"/>
						</td>
					</tr>
					<tr>	
						<th>用户类型</th>
						<td>
							<c:if test="${userEdit.userType eq 1}">普通用户</c:if><c:if test="${userEdit.userType eq 0}">管理员</c:if>
						</td>
					</tr>
					<tr>	
						<th>用户状态</th>
						<td>
							<c:if test="${userEdit.status eq 1}">有效</c:if><c:if test="${userEdit.status eq 0}">无效</c:if>
						</td>
					</tr>
					<tr>
						<th>备注</th>
						<td>
							${userEdit.note }
							<input type="hidden" name="editFormHidden"
						 	 value="[{type:'textarea',id:'userForm.note',name:'userForm.note',value:'${userEdit.note }',showText:'${userEdit.note }'}]"/>
						</td>
					</tr>
				</table>
				</form>
 			</c:if>
		</div>
	</div>
	</body>
</html>
